package cn.yunhe.servlet;

import cn.yunhe.entity.ProductCategory;
import cn.yunhe.service.ProductCategoryService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/GetCategoryServlet")
public class GetCategoryServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int epcid = Integer.parseInt(request.getParameter("epcid"));

        ProductCategoryService pcs = new ProductCategoryService();
        ProductCategory pc = pcs.getCategoryById(epcid);
        int pid = pcs.getParentId(epcid);
        List<ProductCategory>list = pcs.getParents();
        request.setAttribute("pid",pid);
        request.setAttribute("pc",pc);
        request.setAttribute("list",list);
        request.getRequestDispatcher("manage/productClass-modify.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
